package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.FindOrdersDTO;
import com.sky.dto.GoodsSalesDTO;
import com.sky.entity.Order;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    Integer getConfirmed();

    Integer getDeliverInProgress();

    Integer getToBeConfirmed();

    void save(Order order);

    Page<Order> page(Integer status, Long userId);
    @Select("select * from orders where number =#{outTradeNO}")
    Order getByNumber(String outTradeNo);

    void update(Order order);

    Order getById(Long id);
    @Update("update orders set status =6 ,cancel_time=#{now} where id=#{id};")
    void cancel(Long id, LocalDateTime now);
    Page<Order> conditionSearch(FindOrdersDTO findOrdersDTO);

    void confirme(Long id);

    void delivery(Long id);

    void complete(Long id);

    /**
     * 根据订单状态统计订单数量
     * @param status
     * @param orderTime
     * @return
     */
    @Select("select * from orders where status=#{status} and order_time<#{orderTime}")
    List<Order> getByStatusAndOrderTimeTL(Integer status,LocalDateTime orderTime);

    /**
     * 根据动态条件统计营业额数据
     * @param map
     * @return
     */
    Double sumByMap(Map<String, Object> map);
    List<GoodsSalesDTO> getTopTen(LocalDateTime begin,LocalDateTime end);

    Integer countByMap(Map<String, Object> map);
    @Select("select count(orders.id) from orders")
    Integer getAllOrders();
    @Select("select count(0) from orders where status = #{status}")
    Integer getOrdersByStatus(Integer status);
}
